import { UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth } from '@nestjs/swagger';
import { CrudOptions } from '@nestjsx/crud';
import { HandleStatus } from 'libs/db/entity/enum/handle-status.enum';
import { User } from 'libs/db/entity/user.entity';
import { LoggerInfo, moduleLoggerInfo } from '../_decorator/logger-info';

export const UserCrudOps: CrudOptions = {
  model: {
    type: User,
  },
  query: {

    join: {
      area: {
        eager: true
      },
      town: {
        eager: true
      },
      village: {
        eager: true
      },
    },
    exclude: ['updatedAt', 'deleteAt', 'logs', 'password'],
  },
  routes: {
    getManyBase: {
      interceptors: [],
      decorators: [
        UseGuards(AuthGuard('jwt-admin')),
        ApiBearerAuth(),
        LoggerInfo(
          new moduleLoggerInfo('管理员信息查询', HandleStatus.LOG)
        ),
      ],
    },
    getOneBase: {
      interceptors: [],
      decorators: [
        UseGuards(AuthGuard('jwt-admin')),
        ApiBearerAuth(),
        LoggerInfo(
          new moduleLoggerInfo('单个管理员信息查询', HandleStatus.LOG)
        ),
      ],
    },
    createOneBase: {
      interceptors: [],
      decorators: [
        UseGuards(AuthGuard('jwt-admin')),
        ApiBearerAuth(),
        LoggerInfo(
          new moduleLoggerInfo('新增管理员信息', HandleStatus.INFO)
        ),
      ],
      returnShallow: true,
    },
    createManyBase: {
      interceptors: [],
      decorators: [
        UseGuards(AuthGuard('jwt-admin')),
        ApiBearerAuth(),
        LoggerInfo(
          new moduleLoggerInfo('管理员信息上传', HandleStatus.LOG)
        ),
      ],
  },
  replaceOneBase: {
    interceptors: [],
    decorators: [
      UseGuards(AuthGuard('jwt-admin')),
      ApiBearerAuth(),
      LoggerInfo(
        new moduleLoggerInfo('修改管理员信息', HandleStatus.WARN)
      ),
    ],
    allowParamsOverride: true,
    returnShallow: true,
  },
  updateOneBase: {
    interceptors: [],
    decorators: [
      UseGuards(AuthGuard('jwt-admin')),
      ApiBearerAuth(),
      LoggerInfo(
        new moduleLoggerInfo('修改管理员信息', HandleStatus.WARN)
      ),
    ],
    allowParamsOverride: true,
    returnShallow: true,
  },
  deleteOneBase: {
    interceptors: [],
    decorators: [
      UseGuards(AuthGuard('jwt-admin')),
      ApiBearerAuth(),
      LoggerInfo(
        new moduleLoggerInfo('删除管理员信息', HandleStatus.ERROR)
      ),
    ],
    returnDeleted: true,
  },
},
  dto: {
    create: User,
    replace: User,
  },
  serialize: {
    getMany: User,
    get: User,
    create: User,
    createMany: User,
    update: User,
    replace: User,
    delete: User,
  },
};
